package sol.leetcode;

/**
 * Power of Four
 */
public class Issue342 {
    public static boolean isPowerOfFour(int num) {
        // 如果超过1位不是1，那么就肯定不是4的幂次方
        if ((num & (num - 1)) != 0) return false;
        // next check if it's a bit in pos 1, 3, 5 ... 31
        return (num & 0x55555555) != 0;
    }

    public static void main(String[] args) {
        System.out.println(isPowerOfFour(16));
        System.out.println(isPowerOfFour(15));
    }
}
